<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app">
    <!-- <button v-on:click="count--">-</button> -->
    <button @click="jian(count)">-</button>
    <span>{{ count }}</span>
    <button @click="add">+</button>
  </div>
  <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.7.14/vue.js"></script>
  <script>
    const app = new Vue({
      el: '#app',
      data: {
        count: 2
      },
      methods: {
        // 注意 不能使用箭头函数 this指向位window
        jian(a) {
          // Vue中 让methods中的所有函数的this指向Vue实例对象 此时的this指向app
          if (a <= 1) return alert('不能小于1')
          a--
          this.count = a
        },
        add() {
          this.count++
        }
      }
    })
  </script>
</body>

</html>